﻿using Decoration.IRepository;
using Decoration.IService;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Decoration.Service
{
    public class BaseService<T> :BaseQueryService,IBaseService<T> where T : class, new()
    {
        IBaseRepository<T> rep;
        public BaseService(IBaseRepository<T> rep, IBaseQueryRepository brep):base(brep)
        {
            this.rep = rep;
        }
        public bool Add(T t)
        {
            rep.Add(t);
            return rep.SaveChanges();
        }
        public bool Delete(T t)
        {
            rep.Delete(t);
            return rep.SaveChanges();
        }

        public T Get(Expression<Func<T, bool>> whereLambda)
        {
            return rep.Get(whereLambda);
        }

        public IQueryable<T> Query(Expression<Func<T, bool>> whereLambda)
        {
            return rep.Query(whereLambda);
        }

        public bool SaveChanges()
        {
            return rep.SaveChanges();
        }

        public bool Update(T t)
        {
            rep.Update(t);
            return rep.SaveChanges();
        }
    }
}
